package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.Locale;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;

import DataObjects.Bon;
import DataObjects.ConstantObjects;
import DataObjects.FireForManageTableOrder;
import DataObjects.Menu;
import DataObjects.MetaDataOrder;
import DataObjects.Recipe;
import DataObjects.RecipeAdditions;
import Messages.MessageGetFiresByOrderid;
import Messages.MessageGetFiresByOrderidReply;
import Messages.MessageSaveTableOrder;
import Messages.MessageSavingReply;

import javax.swing.UIManager;

import com.sun.jndi.url.iiopname.iiopnameURLContextFactory;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class PfUpdateTableOrder extends JPanel {
	
	
	private MainMenu mainMenu;
	private Vector<Menu> menues;
	private Vector<Bon> bones;
	private Vector<FireForManageTableOrder> fires;
	private MetaDataOrder metaDataOrder;
	private Dimension screenSize;
	private BonPanel bonPanel;
	
	private JPanel menuesPanel;
	private JPanel recipesPanel;
	private int x;
	private int y;
	
	private int coordScrollX;
	private int coordScrollY;
	private int sizeScrollX;
	private int sizeScrollY;
	
	private int coordMenuesX;
	private int coordMenuesY;
	private int sizeMenuesX;
	private int sizeMenuesY;
	
	private int coordRecipesX;
	private int coordRecipesY;
	private int sizeRecipesX;
	private int sizeRecipesY;
	
	private int coordSaveX;
	private int coordSaveY;
	private int sizeSaveX;
	private int sizeSaveY;
	
	private int coordCancelX;
	private int coordCancelY;
	private int sizeCancelX;
	private int sizeCancelY;
	
	private int coordTableNoX;
	private int coordTableNoY;
	private int sizeTableNoX;
	private int sizeTableNoY;
	
	private int coordWaiterNameX;
	private int coordWaiterNameY;
	private int sizeWaiterNameX;
	private int sizeWaiterNameY;
	
	private JPanel recipesAndAdditionsPanel;
	private JPanel extraPanel;
	private JPanel soucePanel;
	private JPanel actionLevelPanel;
	private JPanel additionsPanel;
	private JScrollPane bonPane;
	
	private JPanel textPanel;
	private JTextField text;
	private JLabel commentsLabel;
	
	private boolean bonPanelwasChanged=false;
	private PfUpdateTableOrder pfUpdateTableOrder;

	
	
	public PfUpdateTableOrder(MainMenu mm,Vector<Menu> m,Vector<Bon> vector,MetaDataOrder metaDataOrder,Vector<FireForManageTableOrder> fires)
	{
		super();
		pfUpdateTableOrder=this;
		setBackground(new Color(255, 222, 173));		
		screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		x=screenSize.width;
		y=screenSize.height;
		this.mainMenu=mm;
		this.menues=m;
		this.bones=vector;
		this.metaDataOrder=metaDataOrder;
		if(metaDataOrder.getOrderId()!=null)
		{
		MessageGetFiresByOrderid allFires=new MessageGetFiresByOrderid(metaDataOrder.getOrderId());
		try {
			mainMenu.ms.client.sendToServer(allFires);
			MessageGetFiresByOrderidReply result = (MessageGetFiresByOrderidReply)mainMenu.ms.client.GetMessage();	
			this.fires=result.getVectorFireForManageTableOrder();
		}catch (IOException ei) {
			// TODO Auto-generated catch block
			ei.printStackTrace();
		}
		}
		this.setLayout(null);
		initialize();		
	}

	
	
	
	
	
	private void initialize()
	{	
		//this.add(getBonPanelScroll());
		this.add(getBonPanelScrollAndControlScrollPanel());
		this.add(getMenuesPanel());
		this.add(getRecipesAndAdditionsPanel());
		this.add(getSaveButton());
		this.add(getTableNoLabel());
		this.add(getWaiterNameLabel());
		this.add(getCancelButton());
	}
	
	
	
	private JPanel getTextPanel(final Bon bon)
	{
		textPanel=new JPanel();
		textPanel.setBackground(new Color(255, 222, 173));
		textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS));
		commentsLabel=new JLabel("    הערות :    ");
		commentsLabel.setFont(new Font("Tahoma", Font.ITALIC, 13));
		commentsLabel.setForeground(Color.BLUE);
		text=new JTextField();
		text.addMouseListener(new MouseAdapter()                                                  
        {
            public void mouseClicked(MouseEvent e)                                                                      
            {
            	final VKBLettersAndDigitsPopUp vkbPanel=new VKBLettersAndDigitsPopUp(new Color(200,250,230));                                                                                    
        		vkbPanel.setBounds(4*x/6, y/4, 6*x/14, 2*y/7);
                Point p = text.getLocationOnScreen();
                p.y -= 500;
                p.x-=500;
                vkbPanel.setLocation(p);
                vkbPanel.setVisible(true);
            }
        });
		text.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		commentsLabel.setLabelFor(text);
		text.setPreferredSize(new Dimension(10*x/70,10*y/350));
		text.setMaximumSize(new Dimension(10*x/70,10*y/350));
		text.setMinimumSize(new Dimension(10*x/70,10*y/350));
		if(bon.getComments()!=null)
		{
			text.setText(bon.getComments());
		}
		
		JButton saveCommentsBut=new JButton("שמור הערה");
		saveCommentsBut.setFont(new Font("Tahoma", Font.BOLD, 13));
		saveCommentsBut.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				bon.setComments(text.getText()+"      ");
				bonPanel.removeAll();
				bonPanel.setOrders(bones);
				bonPanel.initialize();
				bonPanel.validate();
				bonPanel.repaint();
				
			}
		});
		
		
		textPanel.add(Box.createHorizontalGlue());
		textPanel.add(saveCommentsBut);
		textPanel.add(text);
		textPanel.add(commentsLabel);
		
		
		
		
		return textPanel;
	}
	
	
	private JPanel getBonPanelScrollAndControlScrollPanel()
	{
	   JPanel bonPanelScrollAndControlScrollPanel=new JPanel();
	   bonPanelScrollAndControlScrollPanel.setBackground(new Color(255, 222, 173));
	   bonPanelScrollAndControlScrollPanel.setLayout(new BoxLayout(bonPanelScrollAndControlScrollPanel, BoxLayout.X_AXIS));
	   bonPanelScrollAndControlScrollPanel.add(getBonPanelScroll());
	   bonPanelScrollAndControlScrollPanel.add(getControlScrollPanel());	
	   
	   coordScrollX=10*x/1000; 
		coordScrollY=0;
		sizeScrollX=10*x/30;
		sizeScrollY=10*y/15;
		bonPanelScrollAndControlScrollPanel.setBounds(coordScrollX,coordScrollY,sizeScrollX, sizeScrollY);
		
	   return bonPanelScrollAndControlScrollPanel;		
	}
	
	
	private JPanel getControlScrollPanel()
	{
		JPanel controlScrollPanel=new JPanel();
		controlScrollPanel.setBackground(new Color(255, 222, 173));
		controlScrollPanel.setLayout(new BoxLayout(controlScrollPanel, BoxLayout.Y_AXIS));
		controlScrollPanel.add(Box.createVerticalGlue());
		controlScrollPanel.add(getUpToEndButton());
		controlScrollPanel.add(getUpButton());
		controlScrollPanel.add(Box.createVerticalGlue());
		controlScrollPanel.add(getDownButton());
		controlScrollPanel.add(getDownToEndButton());
		controlScrollPanel.add(Box.createVerticalGlue());
		
		return controlScrollPanel;
	}
	
	
// ============== Buttons Up, UpToEnd, Down, DownToEnd        for ControlScrollPanel    =======================
	
	private JButton getDownButton()
	{
		Icon downIcon = new ImageIcon("down_icon.png");
		Image img = ((ImageIcon) downIcon).getImage();
		Image newimg = img.getScaledInstance(x/30, x/30,java.awt.Image.SCALE_SMOOTH);
		downIcon = new ImageIcon(newimg);
		JButton downButton=new JButton(downIcon);
		downButton.setVerticalTextPosition(AbstractButton.BOTTOM);
		downButton.setHorizontalTextPosition(AbstractButton.CENTER);
		downButton.setFont(new Font("Tahoma", Font.BOLD, x/90));
		//downButton.setBounds(63*x/100, 11*y/23, 5*x/100, 2*y/24);
		downButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				JScrollBar vertical = bonPane.getVerticalScrollBar();
				vertical.setValue( vertical.getValue()+vertical.getMaximum()/ bonPanel.getComponentCount());							
			}
		});
		
		
		
		
		return downButton;
	}

	
	
	private JButton getDownToEndButton()
	{
		Icon downIcon = new ImageIcon("downToEnd_icon.png");
		Image img = ((ImageIcon) downIcon).getImage();
		Image newimg = img.getScaledInstance(x/30, x/30,java.awt.Image.SCALE_SMOOTH);
		downIcon = new ImageIcon(newimg);
		JButton downButton=new JButton(downIcon);
		downButton.setVerticalTextPosition(AbstractButton.BOTTOM);
		downButton.setHorizontalTextPosition(AbstractButton.CENTER);
		downButton.setFont(new Font("Tahoma", Font.BOLD, x/90));
		//downButton.setBounds(63*x/100, 13*y/23, 5*x/100, 2*y/24);
		downButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				JScrollBar vertical = bonPane.getVerticalScrollBar();
				vertical.setValue( vertical.getMaximum());											
			}
		});

		
		return downButton;
	}

	private JButton getUpToEndButton()
	{
		Icon upIcon = new ImageIcon("upToEnd_icon.png");
		Image img = ((ImageIcon) upIcon).getImage();
		Image newimg = img.getScaledInstance(x/30, x/30,java.awt.Image.SCALE_SMOOTH);
		upIcon = new ImageIcon(newimg);
		JButton upButton=new JButton(upIcon);
		upButton.setVerticalTextPosition(AbstractButton.BOTTOM);
		upButton.setHorizontalTextPosition(AbstractButton.CENTER);
		upButton.setFont(new Font("Tahoma", Font.BOLD, x/90));
		//upButton.setBounds(63*x/100, 14*y/70, 5*x/100, 2*y/24);
		upButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				JScrollBar vertical = bonPane.getVerticalScrollBar();
				vertical.setValue( vertical.getMinimum());								
			}
		});
		
		return upButton;
	}
	
	
	private JButton getUpButton()
	{
		Icon upIcon = new ImageIcon("up_icon.png");
		Image img = ((ImageIcon) upIcon).getImage();
		Image newimg = img.getScaledInstance(x/30, x/30,java.awt.Image.SCALE_SMOOTH);
		upIcon = new ImageIcon(newimg);
		JButton upButton=new JButton(upIcon);
		upButton.setVerticalTextPosition(AbstractButton.BOTTOM);
		upButton.setHorizontalTextPosition(AbstractButton.CENTER);
		upButton.setFont(new Font("Tahoma", Font.BOLD, x/90));
		//upButton.setBounds(63*x/100, 20*y/70, 5*x/100, 2*y/24);
		
		upButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				JScrollBar vertical = bonPane.getVerticalScrollBar();
				vertical.setValue( vertical.getValue()-vertical.getMaximum()/ bonPanel.getComponentCount());								
			}
		});
		
		return upButton;
	}
	
// =========================     END BUTTONS FOR ControlScrollPanel    ==========================================
	
	
	
	
	
	
	private JScrollPane getBonPanelScroll()
	{
		bonPanel=new BonPanel(bones,this,fires);
		bonPanel.setBackground(new Color(250, 250, 210));
		bonPanel.setVisible(true);
		bonPane=new JScrollPane();
		bonPane.setBackground(new Color(255, 222, 173));
		bonPane.setForeground(new Color(255, 222, 173));
		bonPane.setBorder(new TitledBorder(null, " בון ", TitledBorder.CENTER, TitledBorder.TOP, null, null));		
		bonPane.setViewportView(bonPanel);
		
		
				
				
				
		bonPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {       
			public void adjustmentValueChanged(AdjustmentEvent arg0) {				
				if(bonPanelwasChanged)
				{
					arg0.getAdjustable().setValue(arg0.getAdjustable().getMaximum());				
					bonPanelwasChanged=false;
				}							
			}
	    });		
		
		/*coordScrollX=10*x/1000; 
		coordScrollY=0;
		sizeScrollX=10*x/30;
		sizeScrollY=10*y/15;
		bonPane.setBounds(coordScrollX,coordScrollY,sizeScrollX, sizeScrollY);*/
		bonPane.setVisible(true);
		return bonPane;
	}
	
	
	
	
	
	private JPanel getMenuesPanel()
	{
		menuesPanel=new JPanel();
		menuesPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		menuesPanel.setForeground(new Color(240, 255, 240));
		menuesPanel.setBackground(new Color(0, 255, 255));		
		coordMenuesX=coordScrollX+sizeScrollX;
		coordMenuesY=0;
		sizeMenuesX=x-sizeScrollX-10;
		sizeMenuesY=10*y/38;
		menuesPanel.setBounds(coordMenuesX, coordMenuesY,sizeMenuesX,sizeMenuesY);
		menuesPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), " \u05EA\u05E4\u05E8\u05D9\u05D8\u05D9\u05DD ", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 0, 0)));		
		for(int i=0;i<menues.size();i++)
		{
			menuesPanel.add(getMenuButton(menues.get(i),false));
		}		
		return menuesPanel;
	}
	
	
	
	
	private void refreshMenuPanel(Menu menu,Bon bon)
	{
		//menuesPanel.removeAll();
		for(int i=0;i<menuesPanel.getComponentCount();i++)
		{

			MButton mButt=(MButton)menuesPanel.getComponent(i);
			if(mButt.getMenu().getId().equals(menu.getId()))
			{
				mButt.setPressed(true);
			}
			else
			{
				mButt.setPressed(false);
			}
		}	
		
		menuesPanel.validate();
		menuesPanel.repaint();
		
		
	//  remove text panel
		if(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.SOUTH)!=null)
		{
			recipesAndAdditionsPanel.remove(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.SOUTH));
			recipesAndAdditionsPanel.validate();
			recipesAndAdditionsPanel.repaint();
		}
		
		recipesAndAdditionsPanel.add(getTextPanel(bon),BorderLayout.SOUTH);
		recipesAndAdditionsPanel.validate();
		recipesAndAdditionsPanel.repaint();
		
		
	}
	
	
	
	
	
	
	private JPanel getRecipesAndAdditionsPanel()
	{
		recipesAndAdditionsPanel=new JPanel();	
		recipesAndAdditionsPanel.setBackground(new Color(255, 222, 173));
		coordRecipesX=coordScrollX+sizeScrollX;
		coordRecipesY=sizeMenuesY;
		sizeRecipesX=x-sizeScrollX-10;
		sizeRecipesY=y-sizeMenuesY-10*y/50;
		recipesAndAdditionsPanel.setBounds(coordRecipesX, coordRecipesY,sizeRecipesX,sizeRecipesY);
		recipesAndAdditionsPanel.setLayout(new BorderLayout(5,5));		
		recipesAndAdditionsPanel.add(new JScrollPane(getRecipesPanel()),BorderLayout.CENTER);
		//recipesAndAdditionsPanel.add(getTextPanel(),BorderLayout.SOUTH);
		return recipesAndAdditionsPanel;
	}
	
	
	
	/**
	 * this method recieves menu and updates recipes panel with the new buttons 
	 * ( each button is recipe of the given menu that we can to choose 
	 * @param menu
	 * @return flag=0 if they are no items to choose , flag=1 if the menu has minimum 1 recipe to choose
	 */
	private int refreshRecipePanel(Menu menu)
	{
		recipesPanel.removeAll();
		recipesPanel.validate();
		recipesPanel.repaint();
		int flag=0;
		
		for(int i=0;i<menues.size();i++)
		{
			if(menu.getId().equals(menues.get(i).getId()))
			{
				menu=menues.get(i);
				break;
			}
		}
		
		for(int i=0;i<menu.getRecipes().size();i++)
		{
			if(menu.getRecipes().get(i).getIsSelectable()==1)
			{
				recipesPanel.add(getRecipeButton(menu.getRecipes().get(i),menu,false));
				flag=1;
			}
		}
		
		if(flag==1)   //if the menu has any selectable item
		{
			recipesPanel.validate();
			recipesPanel.repaint();
		}
		
		return flag;
	}
	
	
	
	private void refreshRecipePanelPressed(String rid)
	{
		for(int i=0; i<recipesPanel.getComponentCount();i++)
		{
			RButton rButt=(RButton)recipesPanel.getComponent(i);
			if(rButt.getRecipe().getId().equals(rid))
			{
				rButt.setPressed(true);
			}
			else
			{
				rButt.setPressed(false);
			}
		}
		recipesPanel.validate();
		recipesPanel.repaint();
	}
	
	
	
	
	private int refreshAdditionPanel(String rid,Menu m,Bon b)
	{
		Menu menu=null;
		Recipe recipe=null;
		final Bon bon=b;

		for(int i=0;i<menues.size();i++)
		{
			if(menues.get(i).getId().equals(m.getId()))
			{
				menu=menues.get(i);
				break;
			}
		}
		
		for(int j=0;j<menu.getRecipes().size();j++)
		{
			if(menu.getRecipes().get(j).getId().equals(rid))
			{
				recipe=menu.getRecipes().get(j);
				break;
			}
		}
		
		
		
		
		
		additionsPanel=getAdditionsPanel();
		JScrollPane scrollAdditionsPanel=new JScrollPane(additionsPanel);
		if(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
		{
			recipesAndAdditionsPanel.remove(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.EAST));
			recipesAndAdditionsPanel.validate();
			recipesAndAdditionsPanel.repaint();
		}
		int flag=0 ;                                       // flag=0 -> net nikakih tosafot // flag=1-> est tosafot
		
		
		if(recipe.getHasActionLevel()==1)
		{
			flag=1;
			actionLevelPanel=new JPanel();
			actionLevelPanel.setBackground(new Color(255, 255, 200));
			actionLevelPanel.setLayout(new BoxLayout(actionLevelPanel, BoxLayout.Y_AXIS));
			ConstantObjects cons=new ConstantObjects();
			String[] actionLevel=cons.getActionLevel();
			for(int i=0 ; i<actionLevel.length;i++)
			{
				AButton actionLevelButt= new AButton(actionLevel[i],"actionLevel",menu);
				actionLevelButt.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e3) 
					{								
						AButton abut=(AButton)e3.getSource();																
						for(int i=0; i<actionLevelPanel.getComponentCount();i++)
						{
							if(abut==(AButton)actionLevelPanel.getComponent(i))
							{
								if(abut.isPressed)
								{
									abut.setPressed(false);
								}
								else
								{
									abut.setPressed(true);
								}
							}
							
							else
							{
								((AButton)actionLevelPanel.getComponent(i)).setPressed(false);
							}
						}
						
						if(abut.isPressed)
							bon.setActionLevel(abut.getName());
						else
							bon.setActionLevel(null);
						bonPanel.removeAll();
						bonPanel.setOrders(bones);
						bonPanel.initialize();
						bonPanel.validate();
						bonPanel.repaint();									
					}
				});
				actionLevelButt.setPreferredSize(new Dimension(x/15,y/15));
				actionLevelButt.setMaximumSize(new Dimension(x/15,y/15));
				actionLevelButt.setMinimumSize(new Dimension(x/15,y/15));
				actionLevelPanel.add(actionLevelButt);
			}
			additionsPanel.add(actionLevelPanel);

		}
		
		
		
		
		if(recipe.getExtraVector()!=null)
		{
			flag=1;
			extraPanel=new JPanel();
			extraPanel.setBackground(new Color(255, 255, 200));
			extraPanel.setLayout(new BoxLayout(extraPanel, BoxLayout.PAGE_AXIS));
			for(int i=0;i<recipe.getExtraVector().size();i++)
			{
				AButton butt=new AButton(recipe.getExtraVector().get(i).getName(),"extra",recipe.getExtraVector().get(i),menu);
				butt.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) 
					{								
						AButton ebut=(AButton)e.getSource();																
						for(int i=0; i<extraPanel.getComponentCount();i++)
						{
							if(ebut==(AButton)extraPanel.getComponent(i))
							{
								if(ebut.isPressed)
								{
									ebut.setPressed(false);
								}
								else
								{
									ebut.setPressed(true);
								}
							}
							
							else
							{
								((AButton)extraPanel.getComponent(i)).setPressed(false);
							}
						}
						if(ebut.isPressed)
							bon.setExtra(ebut.getRecAdd());
						else
							bon.setExtra(null);
						
						bonPanel.removeAll();
						bonPanel.setOrders(bones);
						bonPanel.initialize();
						bonPanel.validate();
						bonPanel.repaint();

					}
				});
				butt.setPreferredSize(new Dimension(x/15,y/15));
				butt.setMaximumSize(new Dimension(x/15,y/15));
				butt.setMinimumSize(new Dimension(x/15,y/15));
				
				extraPanel.add(butt);
			}
			additionsPanel.add(extraPanel);
		}
		
		
		
		if(recipe.getSouceVector()!=null)
		{
			flag=1;
			soucePanel=new JPanel();
			soucePanel.setBackground(new Color(255, 255, 200));
			soucePanel.setLayout(new BoxLayout(soucePanel, BoxLayout.Y_AXIS));	
			for(int i=0;i<recipe.getSouceVector().size();i++)
			{
				AButton butt=new AButton(recipe.getSouceVector().get(i).getName(),"souce",recipe.getSouceVector().get(i),menu);
				butt.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) 
					{
						AButton sbut=(AButton)e.getSource();												
						for(int i=0; i<soucePanel.getComponentCount();i++)
						{
							if(sbut==(AButton)soucePanel.getComponent(i))
							{
								if(sbut.isPressed)
								{
									sbut.setPressed(false);
								}
								else
								{
									sbut.setPressed(true);
								}
							}									
							else
							{
								((AButton)soucePanel.getComponent(i)).setPressed(false);
							}
						}
						
						if(sbut.isPressed)
							bon.setSouce(sbut.getRecAdd());
						else
							bon.setSouce(null);
						
						bonPanel.removeAll();
						bonPanel.setOrders(bones);
						bonPanel.initialize();
						bonPanel.validate();
						bonPanel.repaint();								
					}
				});
				butt.setPreferredSize(new Dimension(x/15,y/15));
				butt.setMaximumSize(new Dimension(x/15,y/15));
				butt.setMinimumSize(new Dimension(x/15,y/15));
				soucePanel.add(butt);
			}					
			additionsPanel.add(soucePanel);
		}
		// =================================================== TO
		if(flag==1)
		{
			recipesAndAdditionsPanel.add(scrollAdditionsPanel,BorderLayout.EAST);
			recipesAndAdditionsPanel.validate();
			recipesAndAdditionsPanel.repaint();
		}
		
		return flag;
	}
	
	
	
	private void refreshAdditionPanelPressed(Bon bon)
	{
		
		Recipe recipe=null;
		RecipeAdditions extra=bon.getExtra();
		RecipeAdditions souce=bon.getSouce();
		String actionLevel=bon.getActionLevel();
		
		for(int i=0; i<menues.size();i++)
		{
			for(int j=0; j<menues.get(i).getRecipes().size();j++)
			{
				if(menues.get(i).getRecipes().get(j).getId().equals(bon.getRid()))
				{
					recipe=menues.get(i).getRecipes().get(j);
					break;
				}
			}
		}
		
		if(recipe.getExtraVector()!=null)
		{
			for(int i=0; i<extraPanel.getComponentCount();i++)
			{
				AButton butt=(AButton)extraPanel.getComponent(i);
				if(butt.getRecAdd().getId().equals(extra.getId()))
				{
					butt.setPressed(true);
					extraPanel.validate();
					extraPanel.repaint();
				}
				else
				{
					butt.setPressed(false);
					extraPanel.validate();
					extraPanel.repaint();
				}
			}
		}
		
		
		if(recipe.getSouceVector()!=null)
		{
			for(int i=0; i<soucePanel.getComponentCount();i++)
			{
				AButton butt=(AButton)soucePanel.getComponent(i);
				if(butt.getRecAdd().getId().equals(souce.getId()))
				{
					butt.setPressed(true);
					soucePanel.validate();
					soucePanel.repaint();
				}
				else
				{
					butt.setPressed(false);
					soucePanel.validate();
					soucePanel.repaint();
				}
			}
		}
		
		
		
		if(recipe.getHasActionLevel()!=0)
		{
			for(int i=0; i<actionLevelPanel.getComponentCount();i++)
			{
				AButton butt=(AButton)actionLevelPanel.getComponent(i);
				if(butt.getName().equals(actionLevel))
				{
					butt.setPressed(true);
					actionLevelPanel.validate();
					actionLevelPanel.repaint();
				}
				else
				{
					butt.setPressed(false);
					actionLevelPanel.validate();
					actionLevelPanel.repaint();
				}
			}
		}
		
		
		recipesAndAdditionsPanel.validate();
		recipesAndAdditionsPanel.repaint();
		
		
	}
	
	
	private JPanel getAdditionsPanel()
	{
		additionsPanel=new JPanel();
		additionsPanel.setLayout(new BoxLayout(additionsPanel, BoxLayout.X_AXIS));
		additionsPanel.setBorder(new TitledBorder(null, " תוספות ", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		additionsPanel.setBackground(new Color(255, 255, 200));
		return additionsPanel;			
	}
	

	
	
	
	
	
	private JPanel getRecipesPanel()
	{
		recipesPanel=new JPanel();
		recipesPanel.setForeground(new Color(0, 0, 0));
		recipesPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		recipesPanel.setBackground(new Color(255, 255, 224));
		recipesPanel.setBorder(new TitledBorder(null, " מנות ", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		return recipesPanel;
	}
	
	
	
	
	private JButton getSaveButton()
	{
		Icon saveIcon = new ImageIcon("save-icon.png");
		Image img = ((ImageIcon) saveIcon).getImage();
		Image newimg = img.getScaledInstance(40, 40,java.awt.Image.SCALE_SMOOTH);
		saveIcon = new ImageIcon(newimg);
		JButton saveButt=new JButton("שמור",saveIcon);
		saveButt.setBackground(new Color(244, 164, 96)); 
		saveButt.setVerticalTextPosition(AbstractButton.BOTTOM);
		saveButt.setHorizontalTextPosition(AbstractButton.CENTER);
		saveButt.setFont(new Font("Tahoma", Font.BOLD, x/90));
		coordSaveX=0;
		coordSaveY=10*y/15;
		sizeSaveX=10*x/120;
		sizeSaveY=10*y/85;
		saveButt.setBounds(coordSaveX,coordSaveY, sizeSaveX, sizeSaveY);	
		saveButt.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				

				MessageSaveTableOrder msgSave= new MessageSaveTableOrder(bones,metaDataOrder);
				try {
					mainMenu.ms.client.sendToServer(msgSave);
					MessageSavingReply result = (MessageSavingReply)mainMenu.ms.client.GetMessage();
					if(result.getResult()==1)
					JOptionPane.showMessageDialog(null,"הנתונים נשמרו בהצלחה");				
					else
					JOptionPane.showMessageDialog(null,"בעיית תקשורת 03");
					
					mainMenu.getContentPane().remove(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfManageTableOrderPanel(mainMenu,metaDataOrder.getTid()), BorderLayout.CENTER);					
					//mainMenu.getContentPane().add(new PanelFunctionsTables(mainMenu),BorderLayout.EAST);
					mainMenu.getContentPane().validate();
				
				} catch (IOException ei) {
					// TODO Auto-generated catch block
					ei.printStackTrace();
				}
				

			}
		});
		return saveButt;
	}
	
	
	
	
	
	
	
	private JButton getCancelButton()
	{
		Icon cancelIcon = new ImageIcon("cancel-icon.png");
		Image img = ((ImageIcon) cancelIcon).getImage();
		Image newimg = img.getScaledInstance(40, 40,java.awt.Image.SCALE_SMOOTH);
		cancelIcon = new ImageIcon(newimg);
		JButton cancelButt=new JButton("ביטול",cancelIcon);
		cancelButt.setBackground(new Color(244, 164, 96)); 
		cancelButt.setVerticalTextPosition(AbstractButton.BOTTOM);
		cancelButt.setHorizontalTextPosition(AbstractButton.CENTER);
		cancelButt.setFont(new Font("Tahoma", Font.BOLD, x/90));	
		coordCancelX=coordScrollX+sizeScrollX-sizeSaveX;
		coordCancelY=coordSaveY;
		sizeCancelX=sizeSaveX;
		sizeCancelY=sizeSaveY;
		cancelButt.setBounds(coordCancelX,coordCancelY, sizeCancelX, sizeCancelY);	
		cancelButt.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{			
				if(metaDataOrder.isNew()==false)
				{
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().add(new PfManageTableOrderPanel(mainMenu,metaDataOrder.getTid()), BorderLayout.CENTER);					
				mainMenu.getContentPane().validate();		
				}
				if(metaDataOrder.isNew())
				{
					
					mainMenu.getContentPane().remove(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfScheem_All_Tables(mainMenu),BorderLayout.CENTER);
					mainMenu.getContentPane().validate();
				}
			}
		});
		return cancelButt;
	}
	
	
	
	
	
	
	private JLabel getTableNoLabel()
	{
		JLabel tableLabel=new JLabel(" מספר שולחן : "+ metaDataOrder.getTid());
		tableLabel.setForeground(new Color(25, 25, 112));
		tableLabel.setFont(new Font("Tahoma", Font.BOLD, x/90));	
		coordTableNoX=10*x/80;
		coordTableNoY=coordSaveY-y/35;
		sizeTableNoX=10*x/100;
		sizeTableNoY=10*y/100;	
		tableLabel.setBounds(coordTableNoX, coordTableNoY, sizeTableNoX, sizeTableNoY);
		return tableLabel;
	}
	
	
	
	
	
	
	
	private JLabel getWaiterNameLabel()
	{
		JLabel nameLabel=new JLabel(" מלצר: "+ metaDataOrder.getName());
		nameLabel.setForeground(new Color(25, 25, 112));
		nameLabel.setFont(new Font("Tahoma", Font.BOLD, x/90));				
		coordWaiterNameX=coordTableNoX;
		coordWaiterNameY=coordSaveY+y/300;
		sizeWaiterNameX=10*x/100;
		sizeWaiterNameY=10*y/100;	
		nameLabel.setBounds(coordWaiterNameX, coordWaiterNameY, sizeWaiterNameX, sizeWaiterNameY);
		return nameLabel;
	}
	
	
	//=======================================================MENU BUTTON =============================================
	
	private MButton getMenuButton(final Menu menu, boolean isPressed )
	{
		MButton menuButton=new MButton(menu,isPressed);
		//menuButton.setBackground(new Color(244, 164, 96)); 
		menuButton.setVerticalTextPosition(AbstractButton.BOTTOM);
		menuButton.setHorizontalTextPosition(AbstractButton.CENTER);
		menuButton.setFont(new Font("Tahoma", Font.BOLD, x/100));
		menuButton.setPreferredSize(new Dimension(10*x/110,10*y/110));
		menuButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e1) 
			{
				MButton but=(MButton) e1.getSource();
				Menu menu=but.getMenu();
				
				//  remove additions panel
				if(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
				{
					recipesAndAdditionsPanel.remove(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.EAST));
					recipesAndAdditionsPanel.validate();
					recipesAndAdditionsPanel.repaint();
				}
				
				
			//  remove text panelF
				if(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.SOUTH)!=null)
				{
					recipesAndAdditionsPanel.remove(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.SOUTH));
					recipesAndAdditionsPanel.validate();
					recipesAndAdditionsPanel.repaint();
				}
							
							
							
				//set pressed 
				for(int i=0; i<menuesPanel.getComponentCount();i++)
				{
					if(but==(MButton)menuesPanel.getComponent(i))
					{
						if(but.isPressed)
						{
							
						}
						else
						{
							but.setPressed(true);
						}
					}
					
					else
					{
						((MButton)menuesPanel.getComponent(i)).setPressed(false);
					}
				}
				
				
				menuesPanel.validate();
				menuesPanel.repaint();
				recipesPanel.removeAll();
				recipesPanel.validate();
				recipesPanel.repaint();
				int flag=0;
				
				flag=refreshRecipePanel(menu);
				
				if(flag==0)
				{
					Bon bon=new Bon();
					bon.setNew(true);
					bon.setIsFired(0);
					bon.setIsSubmitted(0);
					bon.setMenu(menu);
					bon.setRecipe(null);
					bon.setMid(menu.getId());
					bon.setMname(menu.getName());
					bon.setPrice(menu.getPrice());
					bon.setRid("0");
					bon.setRname("אין");
					bon.setTid(metaDataOrder.getTid());
					bon.setType(menu.getType());
					bon.setEid(metaDataOrder.getEid());
					bon.setComments("אין");
					bones.add(bon);					
					bonPanel.removeAll();
					bonPanel.setOrders(bones);
					bonPanel.initialize();
					bonPanel.validate();
					bonPanel.repaint();
					bonPanelwasChanged=true;
					recipesAndAdditionsPanel.add(getTextPanel(bon),BorderLayout.SOUTH);
					recipesAndAdditionsPanel.validate();
					recipesAndAdditionsPanel.repaint();
				}
			}
		});
		
		
		return menuButton;
	}
	
	
// ==============================================================   RECIPE BUTTON  =================================	
	
	private RButton getRecipeButton(Recipe recipe,Menu m,boolean isPressed)
	{
		RButton recipeButton=new RButton(recipe,m,isPressed);
		recipeButton.setBackground(new Color(244, 164, 96)); 
		recipeButton.setVerticalTextPosition(AbstractButton.BOTTOM);
		recipeButton.setHorizontalTextPosition(AbstractButton.CENTER);
		recipeButton.setFont(new Font("Tahoma", Font.BOLD, x/100));
		recipeButton.setPreferredSize(new Dimension(10*x/110,10*y/110));	
		recipeButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{		
				int flag;
				RButton but=(RButton) e.getSource();
				final Bon bon=new Bon();
				bon.setNew(true);
				bon.setIsFired(0);
				bon.setIsSubmitted(0);
				Menu menu=but.getMenu();
				Recipe recipe=but.getRecipe();
				
			//  remove text panel
				if(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.SOUTH)!=null)
				{
					recipesAndAdditionsPanel.remove(((BorderLayout) recipesAndAdditionsPanel.getLayout()).getLayoutComponent(BorderLayout.SOUTH));
					recipesAndAdditionsPanel.validate();
					recipesAndAdditionsPanel.repaint();
				}
				recipesAndAdditionsPanel.add(getTextPanel(bon),BorderLayout.SOUTH);
				recipesAndAdditionsPanel.validate();
				recipesAndAdditionsPanel.repaint();
				
				bon.setMenu(menu);
				bon.setRecipe(recipe);
				bon.setEid(metaDataOrder.getEid());
				bon.setMid(menu.getId());
				bon.setMname(menu.getName());
				if(menu.getType().equals("simple"))
					bon.setPrice(recipe.getPrice());
				if(menu.getType().equals("business"))
					bon.setPrice(menu.getPrice());
				bon.setRid(recipe.getId());
				bon.setRname(recipe.getName());
				bon.setTid(metaDataOrder.getTid());
				bon.setType(menu.getType());
				bones.add(bon);
				bonPanel.removeAll();
				bonPanel.setOrders(bones);
				bonPanel.initialize();
				bonPanel.validate();
				bonPanel.repaint();
				bonPanelwasChanged=true;
				
				int height=(int)bonPane.getMaximumSize().getHeight()+1;
			
				//set pressed 
				for(int i=0; i<recipesPanel.getComponentCount();i++)
				{
					if(but==(RButton)recipesPanel.getComponent(i))
					{
						if(but.isPressed)
						{
							
						}
						else
						{
							but.setPressed(true);
						}
					}
					
					else
					{
						((RButton)recipesPanel.getComponent(i)).setPressed(false);
					}
				}
				
				
				flag=refreshAdditionPanel(recipe.getId(),menu,bon);

			}
		});		
		return recipeButton;
	}	
//====================================================== END OF RECIPE BUTTON ===============================================	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	private class MButton extends JButton
	{		
		Menu menu;
		boolean isPressed;
		
		private MButton(Menu m ,boolean isPressed)
		{
			super(m.getName());
			setPressed(isPressed);
			menu=m;
		}
		
		
		public boolean isPressed() {
			return isPressed;
		}

		public void setPressed(boolean isPressed) {
			this.isPressed = isPressed;
			if(isPressed)
			{
				this.setBackground(new Color(100,100,100));
			}
			else
			{
				this.setBackground(new Color(244, 164, 96));
			}
			this.validate();
			this.repaint();
		}
		public Menu getMenu() {
			return menu;
		}
		public void setMenu(Menu menu) {
			this.menu = menu;
		}	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	private class AButton extends JButton
	{
		boolean isPressed;
		String name;
		String type;
		RecipeAdditions recAdd;
		Menu menu;		
		
		// button for additions (extra, souce, actionLevel)
		// the button has a type attribute that will tell us the type of addition
		private AButton(String name,String type,RecipeAdditions rec,Menu m)
		{			
			super(name);
			this.name=name;
			this.type=type;
			this.recAdd=rec;
			this.menu=m;
			isPressed=false;
			this.setBackground(new Color(255,240,255));
		}
		
		private AButton(String name,String type,Menu m)
		{			
			super(name);
			this.name=name;
			this.type=type;
			this.menu=m;
			isPressed=false;
			this.setBackground(new Color(255,240,255));
		}

		public boolean isPressed() {
			return isPressed;
		}

		public void setPressed(boolean isPressed) {
			this.isPressed = isPressed;
			if(isPressed)
			{
				this.setBackground(new Color(100,100,100));
			}
			else
			{
				this.setBackground(new Color(255,240,255));
			}
			this.validate();
			this.repaint();
		}
		
		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public RecipeAdditions getRecAdd() {
			return recAdd;
		}

		public void setRecAdd(RecipeAdditions recAdd) {
			this.recAdd = recAdd;
		}

		public Menu getMenu() {
			return menu;
		}

		public void setMenu(Menu menu) {
			this.menu = menu;
		}		
	}
	
	
	
	
	
	
	
	
	
	
	private class RButton extends JButton
	{
		Recipe recipe;
		Menu menu;
		Boolean isPressed;
		
		private RButton(Recipe r,Menu m,boolean isPressed)
		{
			super(r.getName());
			setPressed(isPressed);
			recipe=r;
			menu=m;
		}

		public boolean isPressed() {
			return isPressed;
		}

		public void setPressed(boolean isPressed) {
			this.isPressed = isPressed;
			if(isPressed)
			{
				this.setBackground(new Color(100,100,100));
			}
			else
			{
				this.setBackground(new Color(244, 164, 96));
			}
			this.validate();
			this.repaint();
		}
		public Recipe getRecipe() {
			return recipe;
		}

		public void setRecipe(Recipe recipe) {
			this.recipe = recipe;
		}

		public Menu getMenu() {
			return menu;
		}

		public void setMenu(Menu menu) {
			this.menu = menu;
		}		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * 
	 * @author igor
	 * This class creates panel that will show the current order(bon) 
	 * from chosen table.This panel consists of other panels, then each
	 * panel is the row of the bon . 
	 *
	 */
	public class BonPanel extends JPanel {
		
		private Vector<Bon> orders;
		private PfUpdateTableOrder mainPanel;
		private Vector<FireForManageTableOrder> fires;
		
		public BonPanel (Vector<Bon> ord,PfUpdateTableOrder mainPanel,Vector<FireForManageTableOrder> fires)
		{
			super();
			this.setBackground(new Color(250, 250, 210));
			this.orders=ord;
			this.mainPanel=mainPanel;
			this.fires=fires;
			this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
			initialize();
		}
		
		
		public Vector<Bon> getOrders() {
			return orders;
		}


		public void setOrders(Vector<Bon> orders) {
			this.orders = orders;
		}


		/**
		 * This method adds rows-panels to the bon.
		 */
		private void initialize()
		{
			
			for(int i=0 ; i<orders.size();i++)
			{
				this.add(getOneOrderPanel(orders.get(i),mainPanel));			
			}
		}
		
		
		/**
		 * creates JPanel for one single order of the table
		 * 
		 * @param oneRow is object of Class Bon that includes data about single order from a table 
		 * @return JPanel with the specific data for single order of the table.
		 */
		private JPanel getOneOrderPanel(Bon or,PfUpdateTableOrder m)
		{
			JPanel oneOrder=new JPanel();
			final PfUpdateTableOrder mainPanel=m;
			final Bon oneRow=or;
			String additionsTxt="הערות :";
			oneOrder.setBackground(new Color(250, 250, 210));
			Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			
			oneOrder.setPreferredSize(new Dimension(10*x/41,y/12));
			oneOrder.setMinimumSize(new Dimension(10*x/41,y/12));
			oneOrder.setMaximumSize(new Dimension(10*x/41,y/12));
			
			oneOrder.setLayout(new BorderLayout());
			oneOrder.setOpaque(true);
			JLabel labelName=new JLabel(oneRow.getMname());
			JLabel labelPrice=new JLabel(oneRow.getPrice());
			JLabel labelMana=new JLabel(oneRow.getRname());
			JLabel additionsLabel;
			
			if(oneRow.getComments()!=null && !oneRow.getComments().equals("null") ) 
				additionsTxt=additionsTxt+oneRow.getComments();
		
			
			if(oneRow.getActionLevel()!=null && !oneRow.getActionLevel().equals("null"))
				additionsTxt=additionsTxt+oneRow.getActionLevel()+"   ";
			
			
			if (oneRow.getExtra()!=null  )
				if(oneRow.getExtra().getName()!=null)
				additionsTxt=additionsTxt+oneRow.getExtra().getName()+"   ";
		
			
			if (oneRow.getSouce()!=null )
				if(oneRow.getSouce().getName()!=null)
				additionsTxt=additionsTxt+oneRow.getSouce().getName()+"   ";
				
			
			labelName.setFont(new Font("Tahoma", Font.BOLD, 15));
			labelPrice.setFont(new Font("Tahoma", Font.PLAIN, 16));
			labelMana.setFont(new Font("Tahoma", Font.PLAIN, 11));
			
			labelMana.setHorizontalAlignment(JLabel.CENTER);
			labelName.setHorizontalAlignment(JLabel.CENTER);
			labelPrice.setHorizontalAlignment(JLabel.CENTER);
			
			if(additionsTxt!=null)
			{
				additionsLabel=new JLabel(additionsTxt);
				additionsLabel.setForeground(Color.MAGENTA);
				additionsLabel.setFont(new Font("Tahoma", Font.PLAIN, 11));
				additionsLabel.setHorizontalAlignment(JLabel.CENTER);
				oneOrder.add(additionsLabel,BorderLayout.SOUTH);
				
			}
			
			JButton cancelBut=new JButton("ביטול");
			
			cancelBut.setFont(new Font("Tahoma", Font.BOLD, x/120));
			
			
				/*if(fire.getMid()==Integer.parseInt(oneRow.getMid())&&fire.getRid()==Integer.parseInt(oneRow.getRid()))   
				{
					cancelBut.setEnabled(false);
					fires.removeElementAt(a);
					break;
					
				}*/
				
			if(oneRow.getIsFired()==1)
			{
				cancelBut.setEnabled(false);
				cancelBut.setForeground(Color.red);
				cancelBut.setText("FIRED");
			}
					
			
			
				
		      	cancelBut.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
	      	            
					if(oneRow.isNew())
					{
						   JButton butt=(JButton) e.getSource();
						   bonPanel.remove(butt.getParent());
			               orders.remove(oneRow);
			               bonPanel.validate();
			               bonPanel.repaint();
					}
					
					else
					{
						//JOptionPane.showMessageDialog(null,"eto ne noviy zakaz");
						JButton butt=(JButton) e.getSource();
						CheckPermission checkPermission=new CheckPermission(mainMenu,pfUpdateTableOrder,bonPanel,orders,butt.getParent(),oneRow);
						
					}
					  
				}
			});
			
			
			oneOrder.add(labelMana,BorderLayout.CENTER);
			oneOrder.add(labelName,BorderLayout.NORTH);
			oneOrder.add(labelPrice,BorderLayout.WEST);
			oneOrder.add(cancelBut,BorderLayout.EAST);
			oneOrder.setBorder(new MatteBorder(0, 0, 1, 0, (Color) new Color(0, 0, 0)));
			
			if(oneRow.getIsFired()==0)
			{
			oneOrder.addMouseListener(new MouseListener() {
	            
				@Override
				public void mouseClicked(MouseEvent arg0) {
					mainPanel.refreshMenuPanel(oneRow.getMenu(),oneRow);
					mainPanel.refreshRecipePanel(oneRow.getMenu());
					mainPanel.refreshRecipePanelPressed(oneRow.getRid());
					mainPanel.refreshAdditionPanel(oneRow.getRid(),oneRow.getMenu(), oneRow);
					mainPanel.refreshAdditionPanelPressed(oneRow);
					
				}
				@Override
				public void mouseEntered(MouseEvent arg0) {				
					
					
				}
				@Override
				public void mouseExited(MouseEvent arg0) {	
					
				}
				@Override
				public void mousePressed(MouseEvent arg0) {
									
				}
				@Override
				public void mouseReleased(MouseEvent arg0) {
										
				}
	        });
			} // if(oneRow.getIsFired()==0)
			return oneOrder;
		}
	}

	
	
	
	
	
}
